********************************************************************************
** *TABLE 4: Education Outcomes(HIGH HOPES)
********************************************************************************

use "$merge_scores", clear  



*==============================================================================*
* MBA and LSA treatment
*==============================================================================*

*Reg: column 1, 5 & 6
foreach var of varlist enroll dummy_200 dummy_250 {

	*** Mshwari instrumented with treatment1 and treatment2 ; all sample
	
	*ITT
	xi: reg `var' mshwariorlsa treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2  b_age_imp_dummy b_mpesastatus nb_children_imp, cluster(b_schoolname_baseline_encoded) 
 	summ `var' if e(sample)==1 & control==1 
	estadd local R2 = string(e(r2), "%9.2f")
	estadd local R2a = string(e(r2_a), "%9.2f")
	estadd local cmean=string(r(mean), "%9.2f")
	estimates store `var'_ITT		
	*TOT
	xi: ivreg2 `var' (mshwari_after lsa_after=mshwariorlsa treatment2) i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2  b_age_imp_dummy b_mpesastatus nb_children_imp, cluster(b_schoolname_baseline_encoded) 
	estadd local Papp=string(e(widstat), "%9.0f")
	estadd local PappLM=string(e(idstat), "%9.0f")
	estadd local R2 = string(e(r2), "%9.2f")
	estadd local R2u = string(e(r2u), "%9.2f")
	estadd local R2a = string(e(r2_a), "%9.2f")
	summ `var' if e(sample)==1 & control==1 
	estadd local cmean=string(r(mean), "%9.2f")
	estimates store `var'_TOT
	
}	
 

 

	*ITT
	loc tablist "enroll_ITT dummy_200_ITT dummy_250_ITT" 
	#delimit ;
		esttab `tablist' using "$output/Table_04_Enrol_Score_PanelA.csv",
		replace 
		nolines nogaps nonotes nomtitles nodepvars noobs
		drop(_Istratific_* _cons)
		scalars("R2a Adjusted R-Squared")
		b(%9.2f) se(%9.2f) 
		starlevels(* 0.1 ** 0.05 *** 0.01)
		obslast legend label collabels(none) 
	;
	#delimit cr	
	 
	*TOT
	loc tablist "enroll_TOT dummy_200_TOT dummy_250_TOT"
	#delimit ;
	esttab `tablist' using "$output/Table_04_Enrol_score_PanelB.csv",
	replace 
	nolines nogaps nonotes nomtitles nodepvars 
	drop(_Istratific_* _cons)
	mgroups("Enrollment" "Score 200" "Score 250" , pattern(1  1  1))
	scalars("Papp F-Statistic for weak identification" "R2a  Adjusted R-squared" "cmean Control Mean")
	addnotes("Notes: MBA exposure =1 if MBA treatment=1 OR LSA treatment=1.   LSA exposure=1 if MBA treatment=0 and LSA treatment=1.  The coefficient on LSA exposure reflects the marginal impact of exposure to the LSA relative to exposure to the MBA.   Sample restricted to those with ADS consent and found at endline. Enrollment is a reported indicator if the reference child is currently enrolled in secondary school. In columns 2-4, we report marginal effects of a multinomial probit for the choice of secondary schools for the following categories: non-enrolled, enrolled at community/private/don't know, enrolled in district schools, enrolled in county/national schools. In columns 5-6, indicators for passing score and qualifying scores have thresholds of 200 and 250 respectively calculated from verified national exam test scores. Robust standard errors clustered at school level. Control variables include number of children in the household, a quadratic in respondent's age and indicator variables for primary, secondary school completion and M-PESA use at baseline.  *** significant at 1%, ** significant at 5%, * significant at 10%. Lee Bounds calculated for an indicator for MBA Exposure.")
	b(%9.2f) se(%9.2f) 
	starlevels(* 0.1 ** 0.05 *** 0.01)
	obslast legend label collabels(none) ;
	#delimit cr	



********RUN CMP MODEL FOR ITT MULTINOMIAL PROBIT******

*column 2,3 and 4
cmp setup

cmp (y1= mshwariorlsa treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp, iia) ///
	if enroll!=., ind($cmp_mprobit) vce(cluster b_schoolname_baseline_encoded) nolr qui

margins, dydx(mshwariorlsa treatment2) predict(eq(#2) pr) post
estimates store itt1

cmp (y1= mshwariorlsa treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp, iia) ///
	if enroll!=., ind($cmp_mprobit) vce(cluster b_schoolname_baseline_encoded) nolr qui
margins, dydx(mshwariorlsa treatment2) predict(eq(#3) pr) post
estimates store itt2

cmp (y1= mshwariorlsa treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp, iia) ///
	if enroll!=., ind($cmp_mprobit) vce(cluster b_schoolname_baseline_encoded) nolr qui
margins, dydx(mshwariorlsa treatment2) predict(eq(#4) pr) post
estimates store itt3


esttab itt* using "$output/Table_04_mprobit_ITT.csv", replace nolines nogaps nonotes nomtitles nodepvars b(%9.2f) se(%9.2f) starlevels(* 0.1 ** 0.05 *** 0.01)

********RUN CMP MODEL FOR IV MULTINOMIAL PROBIT ******
cmp (y1= mshwari_after lsa_after i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus , iia) ///
	(mshwari_after=mshwariorlsa i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp) ///
	(lsa_after=treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp)  if enroll!=., ///
	ind($cmp_mprobit $cmp_cont $cmp_cont) vce(cluster b_schoolname_baseline_encoded) nolr qui

margins, dydx(mshwari_after lsa_after) predict(eq(#2) pr) post
estimates store instv1

cmp (y1= mshwari_after lsa_after i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp, iia) ///
	(mshwari_after=mshwariorlsa i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp) ///
	(lsa_after=treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp)  if enroll!=., ///
	ind($cmp_mprobit $cmp_cont $cmp_cont) vce(cluster b_schoolname_baseline_encoded) nolr qui
margins, dydx(mshwari_after lsa_after) predict(eq(#3) pr) post
estimates store instv2

cmp (y1= mshwari_after lsa_after i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp, iia) ///
	(mshwari_after=mshwariorlsa i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp) ///
	(lsa_after=treatment2 i.stratification b_primaryormore b_secondaryormore b_age_imp b_age_imp2 b_age_imp_dummy b_mpesastatus nb_children_imp)  if enroll!=., ///
	ind($cmp_mprobit $cmp_cont $cmp_cont) vce(cluster b_schoolname_baseline_encoded) nolr qui
margins, dydx(mshwari_after lsa_after) predict(eq(#4) pr) post
estimates store instv3


esttab instv* using "$output/Table_04_mprobit_IV.csv", replace nolines nogaps nonotes nomtitles nodepvars b(%9.2f) se(%9.2f) starlevels(* 0.1 ** 0.05 *** 0.01)	




****calculate MBA/LSA complier's' mean in control

local dep_var enroll  school_type2 school_type3 school_type4 dummy_200 dummy_250


**MBA 	
gen mba=.
replace mba=1 if treatment_arm==1 | treatment_arm==2
replace mba=0 if treatment_arm==0

//syntax comp_mean_TOT dep_var treat_var compliance_var
foreach var of varlist `dep_var' {
	
	comp_mean_TOT `var' mba mshwari_after 
	
}	

*LSA
gen lsa = .
replace lsa=1 if treatment_arm==2
replace lsa=0 if treatment_arm==0

foreach var of varlist `dep_var' {
	
	comp_mean_TOT `var' lsa lsa_after 
	
}	
	


exit

Notes: MBA exposure =1 if MBA treatment=1 OR LSA treatment=1.   LSA exposure=1 if MBA treatment=0 and LSA treatment=1.  The coefficient on LSA exposure reflects the marginal impact of exposure to the LSA relative to exposure to the MBA.   Sample restricted to those with ADS consent and found at endline. Enrollment is a reported indicator if the reference child is currently enrolled in secondary school. In columns 2-4, we report marginal effects of a multinomial probit for the choice of secondary schools for the following categories: non-enrolled, enrolled at community/private/don't know, enrolled in district schools, enrolled in county/national schools. In columns 5-6, indicators for passing score and qualifying scores have thresholds of 200 and 250 respectively calculated from verified national exam test scores. Robust standard errors clustered at school level. Control variables include number of children in the household, a quadratic in respondent's age and indicator variables for primary, secondary school completion and M-PESA use at baseline.  *** significant at 1%, ** significant at 5%, * significant at 10%. Lee Bounds calculated for an indicator for MBA Exposure.


















	
	